<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div class="box">
    <h2>我是标题</h2>
    <div class="container">
      <p>我是段落
        <span class="keyword">coderwhy</span>
        哈哈哈
      </p>
      <p>我是段落
        <span class="keyword">coderwhy</span>
        哈哈哈
      </p>
      <div class="article">
        <h3 id="title">我是小标题</h3>
        <p>我是文章的内容,嘿嘿嘿嘿嘿</p>
      </div>
    </div>
  </div>
  <script>
    // 通过导航获取
    var bodyEl = document.body
    var boxEl = bodyEl.firstElementChild
    var containerEl = boxEl.children[1]
    var pEl = containerEl.children[0]
    var spanEl = pEl.children[0]
    console.log(spanEl)
    spanEl.style.color = 'red'

    // 直接获取
    var keywordEls = document.getElementsByClassName("keyword")
    console.log(keywordEls)
    keywordEls[0].style.fontSize = "20px"
    for (var i = 0; i < keywordEls.length; i++) {
      keywordEls[i].style.color = 'red'
    }

    var titleEL = document.getElementById("title")
    titleEL.style.color = 'orange'

    // document.querySelector
    var keywordEl = document.querySelector(".keyword")
    // keywordEls是对象,可迭代的
    var keywordEls = document.querySelectorAll(".keyword")
    console.log(keywordEls)

    var titleEL = document.querySelector("#title")


  </script>
</body>

</html>